package test;

import java.nio.ByteBuffer;

import org.junit.Test;

import hyl.core.MyFun;

public class testbyteBuffer {

	@Test
	public void test1() {
		ByteBuffer bb = ByteBuffer.allocate(8);
	}


	
	//@Test
	public void test2() {
		ByteBuffer bb = ByteBuffer.allocate(20);

		bb.putInt(4);
		// System.out.println(bb.position());
		bb.putInt(12);
		// System.out.println(bb.position());
		bb.put("对对对".getBytes());
		// System.out.println(bb.position());

		bb.flip();
		byte[] dst = new byte[3];
		bb.get(dst);

		byte[] dst1 = new byte[1];
		bb.get(dst1);

		byte[] dst2 = MyFun.concat(dst, dst1);
		System.out.println(MyFun.byteArray2Int(dst2));
		dst1 = new byte[4];
		bb.get(dst1);
		System.out.println(MyFun.byteArray2Int(dst1));
		dst2 = new byte[bb.remaining()];
		bb.get(dst2);
		System.out.println(new String(dst2));
	}
}
